// pages/sign_up_detail/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    inputValue:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({title: options.title})
    this.setData({ title: options.title, name: options.name,...app.globalData.tempData[0]})
    app.globalData.tempData=''
  },
  getInputValue(e){
    this.setData({ inputValue: e.detail.value})
  },
  searchUser(){
    let { inputValue, name, title}=this.data
    if (!inputValue){
      wx.showToast({
        title: '请输入证件号码',
        icon:'none'
      })
    }else{
      wx.redirectTo({
        url: '/pages/sign_up_detail/index?title=' + title+'&&name=' + name,
      })
      wx.showToast({
        title: '暂无查询到相关报名',
        icon: 'none'
      })
    }
  },

  // previewImg
  imgErr(e){
    if (e.target.dataset.index==0){
      this.setData({ recordImg:''})
    } else {
      this.setData({ bibsImg: '' })
    }
  },
  lookImg(e){
    app.previewImg([e.currentTarget.dataset.src])
  },

  saveImageToPhotosAlbum(e) {
    wx.getImageInfo({
      src: e.currentTarget.dataset.src,
      success:function(ret){
        var path = ret.path
        wx.getSetting({
          complete: (res) => {
                  wx.saveImageToPhotosAlbum({
                    filePath: path,
                    success: function (data) {
                      console.log(1)
                      wx.showModal({
                        title: '图片保存成功',
                        content: '图片成功保存到相册了，去发圈噻~',
                        showCancel: false,
                        confirmText: '好哒',
                        confirmColor: '#72B9C3',
                        success: function (res) {
                        }
                      })
                    },
                    fail: function (err) {
                      if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
                        wx.showModal({
                          title: '提示',
                          content: '需要获取权限才能保存到相册',
                          success(res) {
                            if (res.confirm) {
                              wx.openSetting({
                                success(settingdata) {
                                  if (settingdata.authSetting['scope.writePhotosAlbum']) {
                                    wx.showToast({
                                      title: '获取权限成功'
                                    })
                                    console.log('获取权限成功，给出再次点击图片保存到相册的提示。')
                                  } else {
                                    wx.showModal({
                                      title: '提示',
                                      content: '没有权限，人家很难给你保存到相册',
                                      showCancel: false,
                                      confirmText: '好的',
                                      confirmColor: '#72B9C3',
                                      success: function (res) { }
                                    })
                                    console.log('获取权限失败，给出不给权限就无法正常使用的提示')
                                  }
                                }
                              })
                            } else if (res.cancel) {
                              // console.log('用户点击取消')
                            }
                          }
                        })
                      }
                    }
                  })
          },
        })
      }
    })
    console.log(e.currentTarget.dataset.src)
    
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})